﻿Ext.BLANK_IMAGE_URL = "/script/ext/resources/images/s.gif";
Ext.onReady(function () {
    var modelid = jQuery.query.get("modelid");

    //物品名称定义
//    var StockRoomName = new Ext.form.ComboBoxTree({
//        name: "myDepmet",
//        fieldLabel: "物品名称",
//        hiddenName: "ID",
//        listEmptyText: "*暂无信息*",
//        emptyText: "请选择",
//        editable: false,
//        resizable: true,
//        tree: new Ext.tree.TreePanel({
//            root: new Ext.tree.AsyncTreeNode({ text: '文件夹', id: '0', leaf: false }),
//            lines: true,
//            rootVisible: false,
//            border: false,
//            dataUrl: "server/ToStockRoomStuff/StockRoomStuffName.aspx"
//        })
//    });

    var StockRoomName = new Ext.ux.ComboBoxTree({
        fieldLabel: "物品名称",
        hiddenName: "ParentIDss",
        name: "ParentID",
        width: 143,
        emptyText: "请选择",
        editable: false,
        selectNodeModel: 'all',
        tree: {
            xtype: 'treepanel',
            lines: true, rootVisible: false, border: false,
            loader: new Ext.tree.TreeLoader({ dataUrl: 'server/ToStockRoomStuff/StockRoomStuffName.aspx' }),
            root: new Ext.tree.AsyncTreeNode({ text: '选文件夹', id: "0", leaf: false })
        }
    });

    var form = new Ext.form.FormPanel({
        region: 'center',
        title: "出库申请",
        margins: "5",
        layout: 'form',
        frame: true,
        labelAlign: "right",
        labelWidth: 80,
        buttonAlign: "center",
        items: [{ //行1
            layout: 'column', //定义为列模式
            items: [{
                columnWidth: .5, //显示为第一列的宽度33%
                layout: 'form',
                items: StockRoomName
            }, {
                columnWidth: .5, //显示为第一列的宽度33%
                layout: 'form',
                items: [{
                    xtype: 'textfield',
                    name: "ToStockRoomCount",
                    fieldLabel: "物品数量",
                    blankText: '物品数量不能为空',
                    regex: /^[1-9]\d*$/,
                    regexText: "只能输入数字!",
                    allowBlank: false,
                    anchor: '100%'
                }]
            }]
        },
                new Ext.form.HtmlEditor({
                    fieldLabel: '出库说明', //标签名称 
                    anchor: '100%',
                    name: "ToStockRoomContent"
                })],
        buttons: [
                { text: "出库申请", handler: function () {
                    if (form.form.isValid()) {
                        var params = {
                            ToStockRoomName: StockRoomName.getCtValue(),
                            ToStockRoomCount: form.getForm().findField("ToStockRoomCount").getValue(),
                            ToStockRoomContent: form.getForm().findField("ToStockRoomContent").getValue(),
                            ToStockRoomExState: 0
                        };
                        Ext.Ajax.request({
                            url: "server/ToStockRoomStuff/ToStockRoomStuffApply.aspx?modelid=" + modelid,
                            params: params,
                            success: function (response) {
                                var json = Ext.util.JSON.decode(response.responseText);
                                if (json.success) {
                                    Ext.Msg.alert("申请成功", json.msg, function () {
                                        groupStore.load({ params: { start: 0, limit: pageSize} });
                                    });
                                    form.getForm().reset();
                                } else {
                                    Ext.Msg.alert("错误", json.msg);
                                }
                            },
                            failure: function (response) { Ext.Msg.alert("请求失败", response.responseText); }
                        });
                    }
                }
                },
                { text: "重置", handler: function () { form.getForm().reset(); } }
                ]
    });

    /*创建页面布局*/
    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [form]
    }); /*布局加载*/viewport.doLayout();

    /*延时加载*/
    setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 400);

    grid.on('rowdblclick', function (g, index, e) {
        var r = g.getSelectionModel().getSelected();
        StockRoomName.setCtValue(GetFoldersName(r.get("ParentID")), r.get("ParentID"));
//        Ext.get('parent_id').dom.value = r.get("ID");
    });

});